package com.sharesrc.jdev.wiimotedemo.views;

import java.awt.Container;
import java.awt.GridBagConstraints;
import java.util.Arrays;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.sharesrc.jdev.wiimotedemo.common.constant.Constants;
import com.sharesrc.jdev.wiimotedemo.common.constant.Themes;
import com.sharesrc.jdev.wiimotedemo.common.util.UIUtils;

public class GestureModelInfoPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 201308170113L;

	public JLabel lblNumGesturesWasUsedForTraining, lblNumStates, lblNumObservations, lblDefaultProbability, lblQuantizer, lblQuantizerRadius, lblQuantizerHashMap, lblHMM, lblHMMA, lblHMMB, lblHMMPi;
	public JTextField tfNumGesturesWasUsedForTraining, tfNumStates, tfNumObservations, tfDefaultProbability, tfQuantizer, tfQuantizerRadius, tfQuantizerHashMap, tfHMM, tfHMMA, tfHMMB, tfHMMPi;

	GestureModelInfo gestureModelInfo;

	public GestureModelInfoPanel() {
		super();
	}

	public GestureModelInfoPanel(GestureModelInfo gestureModelInfo) {
		this();
		this.gestureModelInfo = gestureModelInfo;
		initUIComponents();
	}

	private void initUIComponents() {
		this.lblNumGesturesWasUsedForTraining = new JLabel(Constants.Texts.NUM_GESTURES_WAS_USED_FOR_TRAINING);
		this.lblNumStates = new JLabel(Constants.Texts.NUM_STATES);
		this.lblNumObservations = new JLabel(Constants.Texts.NUM_OBSERVATIONS);
		this.lblDefaultProbability = new JLabel(Constants.Texts.DEFAULT_PROBABILITY);
		this.lblQuantizer = new JLabel(Constants.Texts.QUANTIZER);
		this.lblQuantizerRadius = new JLabel("     " + Constants.Texts.QUANTIZER_RADIUS);
		this.lblQuantizerHashMap = new JLabel("     " + Constants.Texts.QUANTIZER_HASHMAP);
		this.lblHMM = new JLabel(Constants.Texts.HMM);
		this.lblHMMA = new JLabel("     " + Constants.Texts.HMM_A);
		this.lblHMMB = new JLabel("     " + Constants.Texts.HMM_B);
		this.lblHMMPi = new JLabel("     " + Constants.Texts.HMM_PI);
		this.tfNumGesturesWasUsedForTraining = new JTextField(String.valueOf(this.gestureModelInfo.getNumGesturesWasUsedForTraining()));
		this.tfNumStates = new JTextField(String.valueOf(this.gestureModelInfo.getGestureModel().getNumStates()));
		this.tfNumObservations = new JTextField(String.valueOf(this.gestureModelInfo.getGestureModel().getNumObservations()));
		this.tfDefaultProbability = new JTextField(String.valueOf(this.gestureModelInfo.getGestureModel().getDefaultProbability()));
		this.tfQuantizer = new JTextField("");
		this.tfQuantizerRadius = new JTextField(String.valueOf(this.gestureModelInfo.getGestureModel().getQuantizer().getRadius()));
		this.tfQuantizerHashMap = new JTextField(Arrays.deepToString(this.gestureModelInfo.getGestureModel().getQuantizer().getHashMap()));
		this.tfHMM = new JTextField("");
		this.tfHMMA = new JTextField(Arrays.deepToString(this.gestureModelInfo.getGestureModel().getHMM().getA()));
		this.tfHMMB = new JTextField(Arrays.deepToString(this.gestureModelInfo.getGestureModel().getHMM().getB()));
		this.tfHMMPi = new JTextField(Arrays.toString(this.gestureModelInfo.getGestureModel().getHMM().getPi()));

		addLine(this.lblNumStates, this.tfNumStates);
		addLine(this.lblNumObservations, this.tfNumObservations);
		addLine(this.lblDefaultProbability, this.tfDefaultProbability);
		addLine(this.lblQuantizer, this.tfQuantizer);
		addLine(this.lblQuantizerRadius, this.tfQuantizerRadius);
		addLine(this.lblQuantizerHashMap, this.tfQuantizerHashMap);
		addLine(this.lblHMM, this.tfHMM);
		addLine(this.lblHMMPi, this.tfHMMPi);
		addLine(this.lblHMMA, this.tfHMMA);
		addLine(this.lblHMMB, this.tfHMMB);
		addLine(this.lblNumGesturesWasUsedForTraining, this.tfNumGesturesWasUsedForTraining);

		setBorder(BorderFactory.createMatteBorder(1, 1, 0, 1, Themes.Colore.DETAILED_INFO_PANEL_BORDER));
	}

	private void addLine(JLabel lbl, JTextField tf) {
		addLine(this, lbl, tf);
	}

	private void addLine(Container container, JLabel lbl, JTextField tf) {
		lbl.setOpaque(true);
		lbl.setBackground(Themes.Colore.DETAILED_INFO_PANEL_HEADLINE_BG);
		lbl.setForeground(Themes.Colore.DETAILED_INFO_PANEL_HEADLINE_FG);
		lbl.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Themes.Colore.DETAILED_INFO_PANEL_BORDER), BorderFactory.createEmptyBorder(5, 5, 5, 5)));
		tf.setOpaque(true);
		tf.setEditable(false);
		tf.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Themes.Colore.DETAILED_INFO_PANEL_BORDER), BorderFactory.createEmptyBorder(5, 15, 5, 5)));

		UIUtils.addComponent(container, lbl, 1, 1, 1, 1, GridBagConstraints.BOTH, 0, 0, 0, 0, GridBagConstraints.LINE_START);
		UIUtils.addComponent(container, tf, GridBagConstraints.REMAINDER, 1, 5, 1, GridBagConstraints.BOTH, 0, 0, 0, 0, GridBagConstraints.CENTER);
	}
}
